package com.hyts.classcode.compiler.bean;

import com.hyts.classcode.compiler.config.CompilerConfig;
import lombok.Getter;

import javax.tools.SimpleJavaFileObject;
import java.io.IOException;
import java.net.URI;

/**
 * @project-name:coffice-toolbox
 * @package-name:com.hyts.compiler.bean
 * @author:Libo/Alex
 * @create-date:2019-05-26 23:13
 * @copyright:libo-hyts-github
 * @email:libo2dev@aliyun.com
 * @description:此类主要用于: java object
 */
public class JavaSourceObject extends SimpleJavaFileObject {


    @Getter
    private String sourceCode;

    /**
     * 原生构造器
     * @param uri
     * @param kind
     */
    public JavaSourceObject(URI uri, Kind kind) {
        super(uri, kind);
    }

    /**
     * 便捷构造器
     * @param className
     * @param sourceCode
     */
    public JavaSourceObject(String className, String sourceCode){
        this(URI.create(CompilerConfig.COMPILER_STRING_PREFIX+className+Kind.SOURCE.extension),Kind.SOURCE);
        this.sourceCode = sourceCode;
    }

    /**
     * @param ignoreEncodingErrors
     * @return
     * @throws IOException
     */
    @Override
    public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
        return sourceCode;
    }
}
